VR (Multipass) に対応させる
https://gyazo.com/094b117f85530178268dcb0afbecb352
Unity: 2023.1
Docs
片目でしかレンダリングされない
https://gyazo.com/6702e93499c0df13832a12de08e671bf
VR 対応を行わないと左目しかレンダリングされない
Vertex shader
code:hlsl
struct Attributes
{
float4 positionOS : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID // Add
};
code:hlsl
struct Varyings
{
float4 positionCS : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO // Add
};
code:hlsl
Varyings vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input) // Add; Set "unity_StereoEyeIndex"
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); // Add; Calculate "stereoTargetEyeIndexAsBlendIdx0"
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
return output;
}
(Optional) Fragment shader
https://gyazo.com/2a284364821adc73dbd2e3fe38530e78
Fragment shader で Id を取り扱う場合は追加で実装を行う
code:hlsl
void frag(Varyings input, out half4 outColor : SV_Target0)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); // Add
outColor.rgb = float3(unity_StereoEyeIndex, 0.15, 0.15);
outColor.a = 1.0;
}